<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.xq.shop.po.User"%>
<%@page import="com.xq.shop.util.Const"%>
<%@page import="com.xq.shop.service.user.IOrderService"%>
<%@page import="com.xq.shop.util.UserServiceFactory"%>
<%@page import="com.xq.shop.po.Order"%>
<%@page import="com.xq.shop.po.OrderItem"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
			
	User user = (User) request.getSession().getAttribute(Const.User_Session);
	String param_id = request.getParameter("order_id");
	param_id = "44";
	IOrderService orderService = UserServiceFactory.getOrderService();
	Order order = null;
	if(user != null && param_id != null){
		order = orderService.get(Long.parseLong(param_id));
		if(order.getUser_id() != user.getId()){
			order = null;
		}
	}
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>" />
<jsp:include page="/jsp/common.jsp" />
<jsp:include page="/jsp/tableHead.jsp" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>resource/css/product.css" />
<script type="text/javascript">
$().ready(function(){

	$("a[name='star']").each(function(i, obj){
		$(obj).bind("click", function(){
			$("#score" + $(this).attr("pId")).val($(this).attr("val"));
			$(this).siblings("a").removeClass("active");
			$(this).addClass("active");
		});
	});
});
function submit_score(_pId){

	var data = {
		"product_id" : _pId,
		"order_id" : "<%=order.getId() %>",
		"score" : $("#score" + _pId).val(),
		"content" : $("#content" + _pId).val()
	},
	callback_Fn = function(){
		alert("ok");
	}
	$.post("<%=basePath %>user/score_save.do", data, callback_Fn, "json");
}
</script>
</head>
<body>
<jsp:include page="../header.jsp" />
<div class="content_s">
<div class="bar">
	<table id="listTable" class="ps_list">
		<tr>
			<th>商品信息</th>
			<th>购买时间</th>
			<th>评价状态</th>
		</tr>
<%
	List<OrderItem> list = order.getItems();
	if(order != null && list != null && list.size() > 0){
		for(int i=0, len=list.size(); i<len; i++){
			OrderItem item = list.get(i);
%>
		<tr>
			<td colspan="3">
				<ul>
					<li class="td1 fl">
						<div>
							<div class="fl p-img">
								<a>
									<img width="50" height="50" src="<%=item.getProduct().getImages().get(0).getUrl() %>"/>
								</a>
							</div>
							<div class="fl p-name">
								<a href="<%=basePath %>user/product_info.do?id=<%=item.getProduct_id() %>"><%=item.getProduct_name() %></a>
							</div>
						</div>
					</li>
					<li class="td2 fl">
						<span><%=order.getCreate_date() %></span>
					</li>
					<li class="td3 fl">
						<a>发表评论</a>
					</li>
				</ul>
				<div class="clr"></div>
				<div class="comment_box">
					<div class="box-t">&nbsp;</div>
					<div class="form">
						<div class="form_col">
							<span class="label">
								<em>*</em>评分：
							</span>
							<span class="commstar">
								<a class="star1" val="1" name="star" pId="<%=item.getProduct_id() %>"></a>
								<a class="star2" val="2" name="star" pId="<%=item.getProduct_id() %>"></a>
								<a class="star3" val="3" name="star" pId="<%=item.getProduct_id() %>"></a>
								<a class="star4" val="4" name="star" pId="<%=item.getProduct_id() %>"></a>
								<a class="star5" val="5" name="star" pId="<%=item.getProduct_id() %>"></a>
								<input id="score<%=item.getProduct_id() %>" type="hidden" value="0"/>
							</span>
							<span class="msg_error_01 fl ml10">你的评分是偶们前进的动力</span>
						</div>
						<div class="form_col">
							<span class="label">
								<em>*</em>心得：
							</span>
							<span class="cont">
								<textarea id="content<%=item.getProduct_id() %>" class="area area01">商品是否给力？快分享你的购买心得吧~</textarea>
								<span class="clr"></span>
								<span class="msg_error_01 fl">麻烦填写10-500个字呦</span>
								<span class="msg_txt fr">还可以输入497字</span>
							</span>
						</div>
						<div class="form_col">
							<span class="label">
							</span>
							<span class="cont">
								<span class="submit_a fl mr20" onclick="javascript:submit_score('<%=item.getProduct_id() %>')">评价并继续</span>
								<input type="checkbox" id="anonymous<%=item.getProduct_id() %>"/>
								<label for="anonymous<%=item.getProduct_id() %>" 
									title="匿名评价不会展示您的用户昵称，该评价也不会被第三方网站应用"
								>匿名评价<span class="sign-icon"></span></label>
							</span>
						</div>
					</div>
				</div>
			</td>
		</tr>
<% 
		}
	}
%>
	</table>
</div>
</div>
<jsp:include page="../footer.jsp" />
</body>
</html>